﻿<link rel="stylesheet" href="//at.alicdn.com/t/font_1468998609_1288347.css">
<style>
    .szhlloading {
        -webkit-animation: rotateplane 1.2s infinite ease-in-out;
        animation: rotateplane 1.2s infinite ease-in-out;
    }

    @-webkit-keyframes rotateplane {
        0% {
            -webkit-transform: perspective(120px);
        }

        50% {
            -webkit-transform: perspective(120px) rotateY(180deg);
        }

        100% {
            -webkit-transform: perspective(120px) rotateY(180deg);
        }
    }

    @keyframes rotateplane {
        0% {
            transform: perspective(120px) rotateX(0deg) rotateY(0deg);
            -webkit-transform: perspective(120px) rotateX(0deg) rotateY(0deg);
        }

        50% {
            transform: perspective(120px) rotateY(0deg);
            -webkit-transform: perspective(120px) rotateY(-180.1deg);
        }
    }

    .anchorBL {
        display: none;
    }

    .amap-logo {
        display: none !important;
    }

    .amap-copyright {
        display: none !important;
    }

    #map h3 {
        margin: 0 !important;
    }
</style>
<div style="background: #fbf9fe" ms-controller="MWQQD">
    <div ms-if="isHasDataQX=='Y'">
        <div id="map" style="height: 200px; width: 100%;"></div>
        <div class="weui_cells weui_cells_form">


            <div class="weui_cells_form">
                <div class="weui_cell">
                    <div class="weui_cell_hd" style="display: none;">
                        <label class="weui_label label">签到备注</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <textarea ms-duplex="modelData.QDContent" rows="3" placeholder="请输入签到备注" class="weui_textarea szhl szhl_require"></textarea>
                    </div>
                </div>
            </div>
            <div class="weui_cells weui_cells_form">
                <div class="weui_cell">
                    <div class="weui_cell_bd weui_cell_primary">
                        <input type="text" ms-duplex="modelData.Files" class="wximgupload" style="display: none;" />
                    </div>
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd">
                    <label class="weui_label label">汇报人</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input type="text" id="conCSR" placeholder="请选择汇报人" ms-duplex="modelData.HBUser" class="weui_input szhl szhl_getPeoples" />
                </div>
            </div>
        </div>
    </div>
    <div ms-if="isHasDataQX=='N'">
        <!--<div class="weui_cells_title">基本信息</div>-->
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_hd">
                    <label class="weui_label label">当前位置</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{modelData.Position}}
                </div>
            </div>
            <div class="weui_cells_form">
                <div class="weui_cell">
                    <div class="weui_cell_bd weui_cell_primary">
                        {{modelData.QDContent|html}}
                    </div>
                </div>
            </div>
            <div class="weui_cells weui_cells_form">
                <div class="weui_cell">
                    <div class="weui_cell_bd weui_cell_primary">
                        <div class="viewimg">{{modelData.Files}}</div>
                    </div>
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd">
                    <label class="weui_label label">汇报人</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    {{ComFunJS.convusers(modelData.HBUser)}}
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    $(document).on("click", ".amap-geo", function () {
        if ($("#bz")) {
            $("#bz").text("正在定位中...");
        }
    });

    var map = new AMap.Map('map', function () {
        view: new AMap.View2D({
            //center: new AMap.LngLat(116.397428, 39.90923),
            //zoom: 10
        })
    });
    map.plugin(["AMap.ToolBar"], function () {
        toolBar = new AMap.ToolBar();
        map.addControl(toolBar);
    });
    var geolocation;
    var geocoder;
    map.plugin(["AMap.Geocoder"], function () {
        geocoder = new AMap.Geocoder({
            radius: 1000,
            extensions: "all"
        });
    });
    map.plugin('AMap.Geolocation', function () {
        geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位，默认:true
            timeout: 10000,          //超过10秒后停止定位，默认：无穷大
            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
            zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
            //showButton: false,
            //buttonPosition: 'LB'
        });
        map.addControl(geolocation);
        geolocation.getCurrentPosition();
        AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
        AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
    });

    function onComplete(data) {
        tempmodel.modelData.Longitude = data.position.getLng();
        tempmodel.modelData.Latitude = data.position.getLat();
        var position = [data.position.getLng(), data.position.getLat()];
        //var marker = new AMap.Marker({
        //    map: map,
        //    position: position
        //});
        geocoder.getAddress(position, function (status, result) {
            if (status === 'complete' && result.info === 'OK') {
                geocoder_CallBack(result);
            }
        });
        //$(".load").toggleClass("szhlloading");
    }
    function geocoder_CallBack(data) {
        var address = data.regeocode.formattedAddress; //返回地址描述
        tempmodel.modelData.Position = address;
        tempmodel.Position = address;
        addmarker();
    }
    function onError(data) {
        var str = "定位失败!";
        switch (data.info) {
            case 'PERMISSION_DENIED':
                str += '浏览器阻止了定位操作';
                break;
            case 'POSITION_UNAVAILBLE':
                str += '无法获得当前位置';
                break;
            case 'TIMEOUT':
                str += '定位超时';
                break;
            default:
                str += '未知错误';
                break;
        }
        tempmodel.Position = str;
        //$(".load").toggleClass("szhlloading");
    }
    //查询结果的marker和infowindow
    function addmarker() {
        var lngX = tempmodel.modelData.Longitude;
        var latY = tempmodel.modelData.Latitude;
        //var markerOption = {
        //    map: map,
        //    position: new AMap.LngLat(lngX, latY),
        //    topWhenClick: true
        //};
        //var mar = new AMap.Marker(markerOption);

        var infoWindow = new AMap.InfoWindow({
            content: "<h3 id='bz' style=\"font-size: .8rem;color:#00a6ac;\">  " + tempmodel.Position + "</h3>",//+ TipContents(d.type, d.address, d.tel),
            size: new AMap.Size(300, 0),
            autoMove: true
        });

        infoWindow.open(map, new AMap.LngLat(lngX, latY));
    }

   

    var tempmodel = avalon.define({
        $id: "MWQQD",
        name: "外勤签到",
        ColumnData: [],
        pageType: "edit",
        tpData: [],
        plData: [],
        plcount: 0,
        dataid: "",
        wximg: "",
        Position: "正在定位中...",
        modelData: { "Position": "", "Longitude": "", "Latitude": "", "QDContent": "", "Files": "", "HBUser": "" },
        inittemp: function (strId) {


            if (strId) {

                tempmodel.dataid = strId;
                //编辑加载数据
                $.getJSON('/API/VIEWAPI.ashx?Action=WQQD_GETWQQDMODEL', { P1: strId }, function (resultData) {

                    if (resultData.ErrorMsg == "") {
                        tempmodel.modelData = resultData.Result;

                        tempmodel.plData = resultData.Result1;
                        tempmodel.plcount = resultData.Result1.length;
                        tempmodel.tpData = resultData.Result2;

                        ComFunJS.uploadimgnew(tempmodel.tpData);
                        ComFunJS.viewimg(tempmodel.tpData);
                        if (tempmodel.modelData.RBDate && tempmodel.modelData.RBDate.length > 10) {
                            tempmodel.modelData.RBDate = tempmodel.modelData.RBDate.substring(0, 10);

                            $("#appDate").calendar({
                                value: [tempmodel.modelData.RBDate]
                            });
                        }


                        setTimeout("ComFunJS.initForm();", 500)
                    }
                })
            } else {

                tempmodel.modelData.RBDate = ComFunJS.getnowdate("yyyy-mm-dd");
                if (localStorage.getItem(pmodel.FormCode)) {//判断有没有未保存的表单
                    var tempdata = localStorage.getItem(pmodel.FormCode);//缓存表单数据
                    ComFunJS.winconfirm("系统检测到您未保存的数据,是否加载?", function () {
                        tempmodel.modelData = $.parseJSON(tempdata);
                        ComFunJS.initForm();
                    }, function () {
                        localStorage.removeItem(pmodel.FormCode);
                        ComFunJS.initForm();
                    })
                } else {
                    ComFunJS.initForm();
                }

                ComFunJS.uploadimgnew();

            }
            $('.btnSucc').html('<i class="fa fa-plus"></i>签到');

        },//初始化
        SaveData: function (callback) {
            if (!tempmodel.modelData.Position) {
                top.ComFunJS.winwarning("请先获取位置");
                return;
            }
            tempmodel.modelData.Files = "";
            $("#imglist .tpli").each(function () {
                if ($(this).hasClass("wximg")) { //微信上传未处理的图片
                    if (tempmodel.wximg) {
                        tempmodel.wximg += ",";
                    }
                    tempmodel.wximg += $(this).attr("itemid");

                } else {
                    if (tempmodel.modelData.Files) {
                        tempmodel.modelData.Files = tempmodel.modelData.Files + ',' + $(this).attr("itemid");
                    }
                    else {
                        tempmodel.modelData.Files = $(this).attr("itemid");
                    }
                }

            })

            $.post("/API/VIEWAPI.ashx?ACTION=WQQD_ADDWQQD&r=" + Math.random(), { P1: JSON.stringify(tempmodel.modelData.$model), P2: tempmodel.wximg }, function (result) {
                return callback.call(this, $.parseJSON(result));
            });
        },
        Complate: function () {
            window.location.href = "/View_Mobile/UI/UI_WQQD_LIST.html?r=" + Math.random();
        },
        reload: function () {
            tempmodel.modelData.Position = "";
            tempmodel.Position = "正在定位中...";
            $(".load").toggleClass("szhlloading");
            //circle.getCurrentPosition(locationResult);
            //map.addOverlay(circle);
            geolocation.getCurrentPosition();
        }
    });//# sourceURL=MGZBG.js;
    tempmodel.modelData.$watch("QDContent", function (a, b) {
        if (!pmodel.DataID) {
            localStorage.setItem(pmodel.FormCode, JSON.stringify(tempmodel.modelData.$model));
        }
    })
</script>
